#coding =utf-8
from flask import jsonify,make_response
import json
from webserver.services.dealwith import dealdata
class GetCurRes():
    def __init__(self):
        pass
    def getcurres(self):
        #将读取rundata.log中的数据，并返回给前端，由前端调用
        with open("/root/xiao/project/excelword/rundata/rundata.log",'r',encoding='utf-8') as  f:
            data = f.read()   #str
            data = data.split("----------------------------")  #list
            last_data_index=len(data)-2
            last_data = data[last_data_index].replace("\n","")
            try:
                datelist,casedict,alllist = dealdata(last_data)
                data={
                    "count":len(casedict),
                    "runtime":datelist[0],
                    "case":casedict,
                    "testcaseres":alllist
                }
                # print(data)
                # print(jsonify(data))
                response = make_response(jsonify(data))
                response.headers['Access-Control-Allow-Origin']="*"
                return response
            except:
                data = {
                    "count":1,
                    "message":"接口响应异常"
                }
                response = make_response(jsonify(data))
                response.headers['Access-Control-Allow-Origin'] = "*"
                return response
if __name__=="__main__":
    GetCurRes().getcurres()